package com.zmn.plat.admin.controller.unit;


import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import java.util.List;

import com.zmn.plat.model.entity.base.unit.Unit;
import com.zmn.plat.model.entity.base.unit.UnitQuery;
import com.zmn.plat.services.interfaces.base.unit.UnitService;

/**
 * 基础配置-单位配置表基础查询Controller
 *
 * @author xujie
 * @since 2021-03-01 09:35:57
 */

@Slf4j
@RestController
@RequestMapping("/unit/")
public class UnitListController {

    @Resource
    private UnitService unitService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("/unit/list.action")
    public ModelAndView list(@ModelAttribute UnitQuery query) {

        query.setWhetherLike(true);
        List<Unit> items = unitService.listPageByQuery(query);
        ModelAndView mav = new ModelAndView("unit/list");
        mav.addObject("items", items);
        mav.addObject("vo", query);
        return mav;
    }

    /**
     * 信息
     */
    @RequestMapping("/addEditView")
    @RequiresPermissions("/unit/addEditView.action")
    public ModelAndView info(@RequestParam(value = "unitId", defaultValue = "0") Integer unitId) {

        Unit unit;
        if (unitId == 0) {
            unit = new  Unit();
        } else {
            unit =  unitService.findById(unitId);
        }
        ModelAndView mav = new ModelAndView("unit/detail");
        mav.addObject("unit",  unit);
        return mav;
    }



}
